$(function () {
    $('#keyword').keypress(function (e) {
        var key = e.which; //e.which是按键的值
        if (key == 13) {
            var q = $('#keyword').val();
            if (q && q != '') {
                search('keyword', q)
            }
        }
    });
});

function search(key, value) {
    window.location.href = replaceAndParamVal(window.location, key, value)
}

function replaceAndParamVal(url, paramName, replaceVal, forceAdd) {
    var oUrl = url.toString()
    if (oUrl.indexOf(paramName) != -1) {
        if (forceAdd) {
            var nUrl = ''
            if (oUrl.indexOf('?') != -1) {
                nUrl = oUrl + "&" + paramName + '=' + replaceVal
            } else {
                nUrl = oUrl + "?" + paramName + '=' + replaceVal
            }
            return nUrl;
        } else {
            var re = eval('/(' + paramName + '=)([^&]*)/gi')
            var nUrl = oUrl.replace(re, paramName + '=' + replaceVal)
            return nUrl;
        }
    } else {
        var nUrl = ''
        if (oUrl.indexOf('?') != -1) {
            nUrl = oUrl + "&" + paramName + '=' + replaceVal
        } else {
            nUrl = oUrl + "?" + paramName + '=' + replaceVal
        }
        return nUrl;
    }
}

function searchCategoryid() {
    search('goodsCategoryId', $(event.target).attr('data-goodscategoryid'))
    return false
}
function searchSize() {
    search('goodsSize', $(event.target).attr('data-skuSize'))
    return false
}
function searchColor() {
    search('goodsColor', $(event.target).attr('data-skuColor'))
    return false
}

